package main

func main() {
	println(intToRoman(1994))
}

func intToRoman(num int) string {
	result := ""

	var temp []rune

	thousand := num / 1000
	num %= 1000
	hundred := num / 100
	num %= 100
	ten := num / 10
	num %= 10
	singles := num

	for i := 0; i < thousand; i++ {
		temp = append(temp, 'M')
	}

	if hundred == 4 {
		temp = append(temp, 'C')
		temp = append(temp, 'D')
	} else if hundred == 9 {
		temp = append(temp, 'C')
		temp = append(temp, 'M')
	} else if hundred < 4 {
		for i := 0; i < hundred; i++ {
			temp = append(temp, 'C')
		}
	} else if hundred >= 5 {
		temp = append(temp, 'D')
		for i := 0; i < hundred - 5; i++ {
			temp = append(temp, 'C')
		}
	}

	if ten == 4 {
		temp = append(temp, 'X')
		temp = append(temp, 'L')
	} else if ten == 9 {
		temp = append(temp, 'X')
		temp = append(temp, 'C')
	} else if ten < 4 {
		for i := 0; i < ten; i++ {
			temp = append(temp, 'X')
		}
	} else if ten >= 5 {
		temp = append(temp, 'L')
		for i := 0; i < ten-5; i++ {
			temp = append(temp, 'X')
		}
	}

	if singles == 4 {
		temp = append(temp, 'I')
		temp = append(temp, 'V')
	} else if singles == 9 {
		temp = append(temp, 'I')
		temp = append(temp, 'X')
	} else if singles < 4 {
		for i := 0; i < singles; i++ {
			temp = append(temp, 'I')
		}
	} else if singles >= 5 {
		temp = append(temp, 'V')
		for i := 0; i < singles-5; i++ {
			temp = append(temp, 'I')
		}
	}

	result = string(temp)

	return result
}
